# 【需求02】计算出100-1000内所有质数之和并输出结果，
# 并且计算出整个程序执行花了多长时间。

import time
import math
def get_prime_number_1(n:int):
    # 求约数
    divisor_list = []
    for i in range(2, n):
        num = n % i
        if num == 0:
            divisor_list.append(i)
    # 约数为0是质数
    if len(divisor_list) == 0:
        return True

def get_prime_number_2(n:int):  
    # 求约数
    divisor_list = []
    for i in range(2, int(math.sqrt(n))):   # 更高效
        num = n % i
        if num == 0:
            divisor_list.append(i)
    # 约数为0是质数
    if len(divisor_list) == 0:
        return True

def get_result_1(start:int,end:int):
    result = 0
    for i in range(start, end+1):
        if get_prime_number_1(i):
            # print(i)
            result += i
    return result

def get_result_2(start:int,end:int):
    result = 0
    for i in range(start, end+1):
        if get_prime_number_2(i):
            # print(i)
            result += i
    return result
# 方法一
time_01 = time.time()
a = get_result_1(100,10000)
time_02 = time.time()
print(a)
print(time_02-time_01)
# 方法二，更高效
time_01 = time.time()
a = get_result_2(100,10000)
time_02 = time.time()
print(a)
print(time_02-time_01)
